﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection;

namespace BAL
{
    public partial class Main : Form
    {
        private LoginService.BarcodeJudgeServices bjs = new BAL.LoginService.BarcodeJudgeServices();
     
        private string ID;
        public Main()
        {
            InitializeComponent();
        }

        public Main(string ID)
        {
            InitializeComponent();
            this.ID = ID;
          
        }

        public string JudgeAuthority()
        {
            string result = string.Empty;
            try
            {
                result = bjs.GetPDAAuthority(this.ID);

            }
            catch (Exception ex)
            {
                MessageBox.Show("程序出错！", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button3);
           
            }

            return result;

        }

        public void SetButtonValue()
        {
            btnICStock.Enabled = false;
          
            btnAjustPosition.Enabled = false;
            btnSEOutStock.Enabled = false;
            btnICAlOut.Enabled = false;
            btnICAlIn.Enabled = false;
            btnFastOutStock.Enabled = false;
        }

        private void Main_Load(object sender, EventArgs e)
        {
            label1.Text = Program.user;
            SetButtonValue();
           string action = JudgeAuthority();
           //this.btnAjustPosition.Focus();
            if(action !=null && action !="")
            {
                string[] data = action.Split(',');
                for (int i = 0; i < data.Length; i++)
                {
                    if (data[i] == "AjustPosition")
                    {
                        btnAjustPosition.Enabled = true;
                    }
                    if (data[i] == "ICStock")
                    {
                        btnICStock.Enabled = true;
                    }
                    if (data[i] == "FastOutStock") //快速出库
                    {
                        btnFastOutStock.Enabled = true;
                    }
                 
                    if (data[i] == "SEOutStock")
                    {
                        btnSEOutStock.Enabled = true;
                    }
                    if (data[i] == "ICAlOut")
                    {
                        btnICAlOut.Enabled = true;
                    }
                    if (data[i] == "ICAlIn")
                    {
                        btnICAlIn.Enabled = true;
                    }
                   
                }

            }

        }
        private void btnAjustPosition_Click(object sender, EventArgs e)
        {
            AdjustPosition ap = new AdjustPosition(this.ID);
            ap.Show();
            this.Hide();
        }


        //入库
        //private void button1_Click(object sender, EventArgs e)
        //{
        //    ICStock iw = new ICStock(this.ID);
        //    iw.Show();
        //    this.Hide();
        //}
        //委外
        private void button2_Click(object sender, EventArgs e)
        {
            ICEntrust iw = new ICEntrust(this.ID);
            iw.Show();
            this.Hide();
        }
    
      
        private void bt_next_Click(object sender, EventArgs e)
        {
            Main2 iw = new Main2(this.ID);
            iw.Show();
            this.Hide();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            SEOutStock iw = new SEOutStock(this.ID);
            iw.Show();
            this.Hide();
        }
        //调拨出
        private void button8_Click(object sender, EventArgs e)
        {
            ICAlOut iw = new ICAlOut(this.ID);
            iw.Show();
            this.Hide();
        }
        //调拨入
        private void button7_Click(object sender, EventArgs e)
        {
            ICAlIn iw = new ICAlIn(this.ID);
            iw.Show();
            this.Hide();
        }
      
        private void button11_Click(object sender, EventArgs e)
        {
            Application.Exit();
            //用户存储文件里
            string location = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase.ToString());
            string path = location + "\\Machines.txt";

            FileStream stream = File.Open(path, FileMode.OpenOrCreate, FileAccess.Write);
            stream.Seek(0, SeekOrigin.Begin);
            stream.SetLength(0);
            stream.Close();
        }

        private void button12_Click(object sender, EventArgs e)
        {
            Login iw = new Login();
            iw.Show();
            this.Hide();
        }
        //入库
        private void btnICStock_Click(object sender, EventArgs e)
        {
            ICStock iw = new ICStock(this.ID);
            iw.Show();
            this.Hide();
        }

        private void btnFastOutStock_Click(object sender, EventArgs e)
        {
            FastOutStock iw = new FastOutStock(this.ID);
            iw.Show();
            this.Hide();

        }

       

    }
}